﻿using System;
using System.Diagnostics;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Nuwanda.Common;
using Nuwanda.TfsSpotlight.Shell.Properties;
using Nuwanda.TfsSpotlight.Shell.Services.Interfaces;
using StructureMap;

namespace Nuwanda.TfsSpotlight.Shell.Services
{
    [Author("Bartłomiej Legiędź")]
    [Pluggable("Logger")]
    public class LoggerService : ILogger
    {
        public void WriteActivity(string activity)
        {
            Logger.Write(activity, "ACTIVITY", 100, 1, TraceEventType.Verbose);
        }

        public void WriteError(string error)
        {
            Logger.Write(error, "ERROR", 1, 1, TraceEventType.Error);
        }

        public void WriteWarning(string warning)
        {
            Logger.Write(warning, "WARNING", 1, 1, TraceEventType.Warning);
        }

        public void WriteInformation(string information)
        {
            Logger.Write(information, "INFORMATION", 1, 1, TraceEventType.Information);
        }

        public void WriteException(Exception exception)
        {
            do
            {
                string message = String.Format(Messages.LoggerExceptionFormat, Environment.NewLine, exception.Message, exception.StackTrace);
                Logger.Write(message, "ERROR", 1, 1, TraceEventType.Critical, String.Format(Messages.LoggerExceptionMessage, exception.GetType()));

                exception = exception.InnerException;
            } while (exception != null);
        }
    }
}